using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace HorizontalImageViewer
{
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
            LoadImagesFromFolder(@"D:\testImages"); // 替换为你本地的图像目录
        }

        List<ZoomableImageViewer> _ls = new List<ZoomableImageViewer>();

        private void LoadImagesFromFolder(string folder)
        {
            if (!Directory.Exists(folder)) return;

            _ls.Clear();
            var files = Directory.EnumerateFiles(folder)
                        .Where(f => f.EndsWith(".jpg") || f.EndsWith(".png") || f.EndsWith(".bmp")||f.EndsWith(".tif"));

            foreach (var file in files)
            {
                var viewer = new ZoomableImageViewer();
                viewer.LoadImage(file);

                _ls.Add(viewer);
                imagePanel.Children.Add(viewer);
            }
        }

        private double zoomFactor = 1.1; // 缩放比例
        private double minZoom = 1;
        private double maxZoom = 10;
        double newScale = 1;
        double ScaleX = 1;
        private void BtnZoomIn_Click(object sender, RoutedEventArgs e)
        {
            double newScale = ScaleX * zoomFactor;
            if (newScale < maxZoom)
            {
                ScaleX  = newScale;

                _ls.ForEach(viewer => viewer.Zoom(ScaleX));
            }
        }

        private void BtnZoomOut_Click(object sender, RoutedEventArgs e)
        {
            double newScale = ScaleX / zoomFactor;
            if (newScale > minZoom)
            {
                ScaleX = newScale;
                _ls.ForEach(viewer => viewer.Zoom(ScaleX));
            }
        }

        private void BtnReset_Click(object sender, RoutedEventArgs e)
        {
            ScaleX = 1.0;
            _ls.ForEach(viewer => viewer.Zoom(ScaleX));

        }
    }
}